package comp418.blingo;

import comp418.blingo.create.bt_raiseQ;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
 * 
 * @author Jingbang
 *
 */
public class answer extends Activity {
private Utility utility=null;
	
	
	private Button bt_answer;
	private Context mContext;
	private EditText content;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.answer);
		utility=Utility.getUtility();
		mContext=this;
		
		
	
		content=(EditText)findViewById(R.id.answercontent);
		bt_answer=(Button) findViewById(R.id.answerit);
		
		bt_answer.setOnClickListener(new bt_raiseQ());
		
		
		
	}
	
	class bt_raiseQ implements android.view.View.OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			
			String qContent=content.getText().toString();
			int currentID=utility.getQid();
			if( qContent!=null &&  !qContent.equals("")){
				//send the answer
				//TODO: answer
				//get the response
				//show success text
				boolean result=false;
				result=utility.answerQuestion(qContent, currentID);
				if(result){
					utility.showToast(mContext, "answer successful!");
					Intent intent=new Intent();
					String user=utility.getUsername();
					intent.putExtra("username", user);
					intent.setClass(answer.this,description.class);
				
					answer.this.startActivity(intent);
				}else
					utility.showToast(mContext, "please try again!");
			}else{
				utility.showToast(mContext, "Please complete all fields!");
			}

		}
	}

}
